<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
    .box{
      width: 100px;
      height: 100px;
      background-color: red;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    @keyframes shake-from {
      0% {
        opacity: 0;
        transform: translateX(0);
      }
      50% {
        opacity: 0.5;
        transform: translateX(50px);
      }
      100% {
        opacity: 1;
        transform: translateX(0);
      }
    }

    @keyframes shake-to {
      0% {
        opacity: 1;
        transform: translateX(0);
      }
      50% {
        opacity: 0.5;
        transform: translateX(50px);
      }
      100% {
        opacity: 0;
        transform: translateX(0);
      }
    }

    .v-enter-from{
      opacity: 0;
    }
    .v-enter-active{
      /*过渡*/
      transition: all 2s ease-in;
      /*动画*/
      animation: 2s shake-from;
    }
    .v-leave-active{
      /*过渡*/
      transition: all 2s ease-in;
      /*动画*/
      animation: 2s shake-to;
    }
    .v-enter-to{
      opacity: 1;
    }
    .v-leave-to{
      opacity: 0;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>{{ msg }}</h1>
  </div>
  <script src="js/vue.js"></script>
  <script>
    const app = Vue.createApp({
      data() {
        return {
          msg: '撩课学院',
          flag: false
        }
      },
      methods:{
        beforeEnter(el){
          el.style.borderRadius = '0%';
        },
        enter(el, done){
          console.log('来了----');
           const intervalId = setInterval(()=>{
               const radius = el.style.borderRadius;
               if(radius === '0%'){
                  el.style.borderRadius = '50%';
               }else{
                 el.style.borderRadius = '0%';
               }
           }, 1000);

           // 10s之后进入动画完成
          setTimeout(()=>{
             clearInterval(intervalId);
             done();
          }, 3000);
        },
        afterEnter(el){
            console.log('afterEnter()');
            el.style.borderRadius = '0%';
            el.style.backgroundColor = 'green';
        }
      },
      template: `
        <div>
           <transition
             :css="false"
             @before-enter="beforeEnter"
             @enter="enter"
             @after-enter="afterEnter"
           >
               <div class="box" v-show="flag">{{msg}}</div>
           </transition>
           <button @click="flag = !flag">显示/隐藏</button>
        </div>
      `
    }).mount('#app');
  </script>
</body>
</html>
